package basic_1004;
import java.util.Scanner;

public class Main {

	static int day;
	static int hour;
	static int minite;
	
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		
		String str_1=scanner.next();
		String str_2=scanner.next();
		String str_3=scanner.next();
		String str_4=scanner.next();
		scanner.close();
		
		getDayAndHour(str_1,str_2);
		
		getMinite(str_4,str_3);
		
		String[] dayChar= {"MON","TUE","WED","THU","FRI","SAT","SUN"};
		String dayStr=dayChar[day];
		String hourStr=hour<10?"0"+hour:""+hour;
		String minStr= minite<10?"0"+minite:""+minite;
		
		System.out.println(dayStr+" "+hourStr+":"+minStr);
	}
	
	static void getDayAndHour(String sStr,String lStr) {
		
		if(sStr.length()>lStr.length()) {
			getDayAndHour(lStr, sStr);
			return;
		}
		
		boolean getDay=false;
		
		int dayIndex = 0;
		int hourIndex = 0;
		for(int i=0;i<sStr.length();i++) {
			
			char c1=sStr.charAt(i);
			char c2=lStr.charAt(i);
			
			if(c1!=c2) {
				continue;
			}
			
			if(!getDay) {
				if(c1>='A'&&c1<='G') {
					dayIndex=i;
					getDay=true;
				}
			}else{
				if((c1>='A'&&c1<='N')||(c1>='0'&&c1<='9')) {
					hourIndex=i;
					break;
				}
			}
		}
		
		day=lStr.charAt(dayIndex)-'A';
		hour=lStr.charAt(hourIndex)>='A'?lStr.charAt(hourIndex)-'A'+10:lStr.charAt(hourIndex)-'0';
	}
	
	static void getMinite(String sStr,String lStr) {
		if(sStr.length()>lStr.length()) {
			getMinite(lStr, sStr);
			return;
		}
		for(int i=0;i<sStr.length();i++) {
			if(lStr.charAt(i)==sStr.charAt(i)) {
				char c=lStr.charAt(i);
				if((c>='a'&&c<='z')||(c>='A'&&c<='Z')) {
					minite=i;
					return;
				}
			}
		}
	}
}
